USE [Data]
GO

/****** Object:  View [InventarioVentas].[vw_lotes]    Script Date: 02/18/2013 15:41:55 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[InventarioVentas].[vw_lotes]'))
DROP VIEW [InventarioVentas].[vw_lotes]
GO

USE [Data]
GO

/****** Object:  View [InventarioVentas].[vw_lotes]    Script Date: 02/18/2013 15:41:55 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE VIEW [InventarioVentas].[vw_lotes] as

SELECT
CP.IdProyecto As 'Codigo_Urbanizacion',
A1.IdEdificacion As 'Codigo_Proyecto',
A1.IdProductoInventariable AS 'Codigo_Lote',
A1.IdUbicacion1 AS Manzana,
A1.IdUbicacion3 AS Lote,
ISNULL((select EC.Descripcion
				from  Data.InventarioVentas.ProductoConstruccion AS PC
					INNER JOIN Configuracion.ListaVirtualConsultarPorNombre('EstadosConstruccion') AS EC
						ON PC.IdEstadoConstruccion = EC.Id
								WHERE PC.IdProductoInventariable = A1.IdProductoInventariable),'STANDBY') AS estado_construccion,
A1.Area As 'area_terreno',
A3.PlazoCuotaEntrada as 'plazo_entrada',
A3.PlazoEntrega as 'plazo_entrega'
FROM Data.InventarioVentas.ProductoInventariable AS A1
--INNER JOIN Data.InventarioVentas.ProductoConstruccion AS A2
--ON A1.IdProductoInventariable = A2.IdProductoInventariable
INNER JOIN  Data.Configuracion.Proyecto CP
	ON A1.IdPersonaPromotor=CP.IdCorredorDefault
	AND A1.IdEstadoComercial IN (1)
	and A1.VenderComo=1
INNER JOIN Data.InventarioVentas.ProductoInventariableParametroNegociacion AS A3
ON A3.IdProductoInventariable = A1.IdProductoInventariable
AND A3.IdTipoFinanciamiento='C'
and A3.VenderComo=1
--where A1.IdEdificacion=3
--WHERE A1.IdProductoInventariable=11151
--ORDER BY 3,4,5


GO

